package contactbook.dao.impl;

import java.util.HashMap;
import java.util.Set;

import contactbook.dao.GroupDAOInterface;
import contactbook.model.Group;

public class GroupDAO implements GroupDAOInterface {
	
	private static int cmpt = 0;
	
	private HashMap<Integer, Group> groups;
	
	public GroupDAO() {
		groups = new HashMap<Integer, Group>();
	}
	
	@Override
	public Group addGroup(Group group) {
		group.setId(getNextId());
		groups.put(group.getId(), group);
		return group;
	}

	@Override
	public void deleteGroup(int groupId) {
		groups.remove(groupId);	
	}

	@Override
	public Group getGroupById(int groupId) {
		return groups.get(groupId);
	}
	
	public boolean exists(int groupId) {
		return groups.containsKey(groupId);
	}
	
	public boolean exists(Group g) {
		return groups.containsValue(g);
	}
	
	private static int getNextId() {
		return ++cmpt;
	}
}
